import { createRouter, createWebHistory } from 'vue-router'
import AdminPage from '@/components/admin/AdminPage.vue'
import UserPage from '@/components/user/UserPage.vue'
import LoginView from '@/components/LoginView.vue'

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'LoginPage',
    component: LoginView
  },
  {
    path: '/admin',
    name: 'AdminPage',
    component: AdminPage
  },
  {
    path: '/user',
    name: 'UserPage',
    component: UserPage
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  const isLogin = to.path === '/login'
  if (isLogin) {
    document.body.style.overflow = 'hidden'
  } else {
    document.body.style.overflow = 'auto'
  }

  next()
})

export default router // 确保导出路由实例
